package com.summer.safe.controller.system;

import com.summer.safe.base.BaseController;
import com.summer.safe.utils.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 */
@Controller
@RequestMapping("/tree")
public class TreeController extends BaseController {
    private final static String URL_FIELD = "url";
    private final static String TYPE_FIELD = "type";
    private final static String OFFICE_URL = "/sys/office/treeData";
    private final static String USER_URL = "/sys/user/treeData";
    private final static String AREA_URL = "/sys/area/treeData";

    @RequestMapping(value = "")
    public String selectTree(HttpServletRequest request) {
        Map<String, String[]> params = request.getParameterMap();
        params.forEach((k, v) -> request.setAttribute(k, v[0]));

        String url = getParameter(URL_FIELD);
        String type = getParameter(TYPE_FIELD);
        String[] urls = {url, OFFICE_URL, USER_URL, AREA_URL};
        int i = StringUtils.isEmpty(url) && StringUtils.isNotEmpty(type) ? Integer.parseInt(type) : 0;
        request.setAttribute("url", urls[i]);
        return "/common/tree.html";
    }


}
